{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7c696475",
   "metadata": {},
   "source": [
    "------\n",
    "* 本学习记录人：陈依玟\n",
    "* 学习时间：2021-11-09\n",
    "* week11\n",
    "* 参考的文档：\n",
    "> 1.[Python的官方文档]（https://docs.python.org/3/）\n",
    "> 2.[许老师的博客]（https://www.cnblogs.com/xuzhichao/p/11407192.html）\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56e36e8a",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "## 1.用户输入（input）\n",
    "\n",
    "> 1.数据从 服务端定义--> 客户端 用户输入数据 的转变\n",
    "> 2.注意： input需要用户执行完，才可以执行后面的代码\n",
    "\n",
    "* 实践：用户登录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ad35d319",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账号：evenchan\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入您的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "16683e33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "evenchan\n"
     ]
    }
   ],
   "source": [
    "print(username)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "efed3413",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账号Alex\n",
      "登陆成功~\n"
     ]
    }
   ],
   "source": [
    "# 1.假如有一个用户数据（账号）在数据库  username_data  中\n",
    "\n",
    "username_data = \"Alex\"  # 服务端 定义数据\n",
    "\n",
    "username = input(\"请输入您的账号\") #  客户端 数据（用户输入，用户交互行为等）\n",
    "\n",
    "# 2. 如果用户输入的账号等于数据库账号， 登陆成功（条件判断）\n",
    "if username == username_data:\n",
    "    print(\"登陆成功~\")\n",
    "else:\n",
    "    print(\"您输入的账号有误~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "270d007e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C Y\n",
      "CY\n"
     ]
    }
   ],
   "source": [
    "print(\"C\",\"Y\")\n",
    "print(\"C\"+\"Y\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "a68d94de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function print in module builtins:\n",
      "\n",
      "print(...)\n",
      "    print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n",
      "    \n",
      "    Prints the values to a stream, or to sys.stdout by default.\n",
      "    Optional keyword arguments:\n",
      "    file:  a file-like object (stream); defaults to the current sys.stdout.\n",
      "    sep:   string inserted between values, default a space.\n",
      "    end:   string appended after the last value, default a newline.\n",
      "    flush: whether to forcibly flush the stream.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(print)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "75ac8966",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账号：Jack0101\n",
      "请输入您的密码：12345678\n",
      "登陆成功,欢迎 Jack0101 回来~\n"
     ]
    }
   ],
   "source": [
    "# 实践：实现用户登录系统(尝试除了账号之外，还要判断密码)\n",
    "\n",
    "# 服务端 定义数据：1. username_data   2.password_data\n",
    "import time\n",
    "username_database = \"Jack0101\"\n",
    "password_database = \"12345678\"\n",
    "\n",
    "# 思考： 用户只给3次机会， 3次过后， 5分钟之后再给输入机会\n",
    "count = 3\n",
    "while True: \n",
    "    count -= 1 # 等价于 count = count + 1\n",
    "    username = input(\"请输入您的账号：\")\n",
    "    password = input(\"请输入您的密码：\")\n",
    "    # 1. 判断账号\n",
    "    if username_database == username:\n",
    "    #2. 账号正确的前提下，判断密码的两种可能\n",
    "        if password_database == password:\n",
    "            print(\"登陆成功,欢迎\",username,\"回来~\")\n",
    "            break\n",
    "        else:\n",
    "            if count>0:\n",
    "                print(\"您输入的账号不存在或者密码有误，请重新输入！您还有\",count,\"次输入机会\")\n",
    "            else:\n",
    "                print(\"您已经输入3次不正确，5秒后尝试，自己的账号都记不住！笨死了\")\n",
    "                time.sleep(5)\n",
    "                count = 3 # 输入次数重置回3次\n",
    "    else:\n",
    "        if count>0:\n",
    "            print(\"您输入的行号不存在或者密码有，请重新输入！您还有\",count,\"次输入机会\")\n",
    "        else:\n",
    "            print(\"您已经输入3次不正确，5秒后尝试，自己的账号都记不住！笨死了\")\n",
    "            time.sleep(5)\n",
    "            count = 3                \n",
    "   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d312ae2",
   "metadata": {},
   "source": [
    "## 2.while 循环\n",
    "\n",
    "* while True 无限循环！什么时候用？\n",
    "> 1. 当不清楚何时使用while True（回顾， 当我们清楚循环次数时用？for + range）\n",
    "> 2. while True也可以决定**循环次数**：使用计数器count的方法\n",
    "> 3. while True也可以根据**条件**退出循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8d39981",
   "metadata": {},
   "outputs": [],
   "source": [
    "# for i in range(无穷大？)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ab43104c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n",
      "你是风儿\n"
     ]
    }
   ],
   "source": [
    "count = 0 # 记录循环的次数\n",
    "\n",
    "while True:\n",
    "    print(\"你是风儿\")\n",
    "    count = count + 1\n",
    "    if count == 100:\n",
    "        break # 停止循环，跳出 循环体\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10434d43",
   "metadata": {},
   "source": [
    "## 3. 格式化文本\n",
    "\n",
    "> 1. 占位符 %s: s 指的是  str\n",
    ">>1. %s 代表string\n",
    ">>2. %d 代表number\n",
    ">>3. %f 代表float"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "df710b78",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-7-43b434338d46>, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-7-43b434338d46>\"\u001b[1;36m, line \u001b[1;32m12\u001b[0m\n\u001b[1;33m    salary:%s'''%（name,name,age,job,salary）  # 按照出现的次序依次填写变量\u001b[0m\n\u001b[1;37m                                                            \n^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "# 1.字符串的拼接，用户的详细信息\n",
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "\n",
    "info ='''----INFO  OF %s------\n",
    "nane:%s\n",
    "age:%s\n",
    "job:%s\n",
    "salary:%s'''%（name,name,age,job,salary）  # 按照出现的次序依次填写变量\n",
    " #优势： 避免字符串拼接出现的语法错误\n",
    " #劣势：如果有很多很多占位符，顺序有可能出错，容易出现顺序的差错\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5d4ae298",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-6-cdb866d8327d>, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-6-cdb866d8327d>\"\u001b[1;36m, line \u001b[1;32m12\u001b[0m\n\u001b[1;33m    salary:{薪水}'''，format{姓名=name,年龄=age，工作=job，薪水=salary}\u001b[0m\n\u001b[1;37m                                                          \n^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "# 3.字符串的格式化： str.format（）\n",
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "\n",
    "info ='''----INFO  OF {姓名}------\n",
    "nane:{姓名}\n",
    "age:{年龄}\n",
    "job:{工作}\n",
    "salary:{薪水}'''，format{姓名=name,年龄=age，工作=job，薪水=salary}\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cdd052d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LXT\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d172bcb",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aace8324",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34e77288",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
